package org.collector.process;

import org.collector.baseoper.ClientsWithStatu;
import org.collector.util.CanbeClosedRunnable;

public class TaskProcessRunnable extends CanbeClosedRunnable {
	private ClientsWithStatu clientsWithStatu;
	private final static int EXC_FAIL_WAIT_TIME = 1 * 1000;
	private final static int QUE_ZERO_WAIT_TIME = 5 * 1000;
	public TaskProcessRunnable(ClientsWithStatu clientsWithStatu){
		this.clientsWithStatu = clientsWithStatu;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(true){
			if(clientsWithStatu.getTotalQueueLen() > 0){
				if(!clientsWithStatu.execute()){
					try {
						Thread.sleep(EXC_FAIL_WAIT_TIME);
					} catch (InterruptedException e) {
					}
				}
			}
			else{
				if(isClosed())
					break;
				else{
					try {
						Thread.sleep(QUE_ZERO_WAIT_TIME);
					} catch (InterruptedException e) {
					}
				}
			}
		}
	}

}
